package com.hc.bank.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class AjaxServlet extends HttpServlet {

	private static final long serialVersionUID = 7740782667902409285L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		
		String id = request.getParameter("id");
		System.out.println("-------------" + id);
		// 改调用Services 就调用Services

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", 1001);
		map.put("userName", "张三");
		list.add(map);
		
		map = new HashMap<String, Object>();
		map.put("id", 1002);
		map.put("userName", "李四");
		list.add(map);
		
		map = new HashMap<String, Object>();
		map.put("id", 1002);
		map.put("userName", "王五");
		list.add(map);
		
		
		// JSON			
		String json = JSON.toJSONString(list);
		out.println(json);
		out.flush();
		
		
	}

}
